#ifndef 	I2C_INIT_H_
#define		I2C_INIT_H_

#include <stdint.h>  
/* STM32 I2C 速率 */
 #define I2C_Speed 													100000
 
 /* STM32 自身的 I2C 地址，这个地址只要与 STM32 外挂的 I2C 器件地址不一样即可 */
 #define I2C_OWN_ADDRESS7 									0X0A
 
 /*I2C 接口*/
 #define DS3231_I2C 								I2C2
 #define DS3231_I2C_CLK 							RCC_APB1Periph_I2C2
 
 #define DS3231_I2C_SCL_PIN 						GPIO_Pin_1
 #define DS3231_I2C_SCL_GPIO_PORT 					GPIOF
 #define DS3231_I2C_SCL_GPIO_CLK 					RCC_AHB1Periph_GPIOF
 #define DS3231_I2C_SCL_SOURCE 						GPIO_PinSource1
 #define DS3231_I2C_SCL_AF 							GPIO_AF_I2C2
 
 #define DS3231_I2C_SDA_PIN 						GPIO_Pin_0
 #define DS3231_I2C_SDA_GPIO_PORT 					GPIOF
 #define DS3231_I2C_SDA_GPIO_CLK 					RCC_AHB1Periph_GPIOF
 #define DS3231_I2C_SDA_SOURCE 						GPIO_PinSource0
 #define DS3231_I2C_SDA_AF 							GPIO_AF_I2C2
 
extern void I2C_GPIO_Config(void);
extern void I2C_Mode_Config(void);
extern void I2C_EE_Init(void); 
extern uint8_t I2cByteRead(uint8_t nAddr);
extern void I2cByteWrite(uint8_t addr, uint8_t data);

extern void I2C_START(void);
extern void I2C_STOP(void);
extern void I2C_Tack(void);
extern void I2C_NOACK(void);
extern void I2C_write_byte(unsigned char Data);
unsigned char I2C_read_byte(void);
extern void I2C_single_byte_write(unsigned char Waddr, unsigned char Data);
extern unsigned char I2C_single_byte_read(unsigned char Waddr);
extern void I2C2_Init(void);

extern void DS3231_Init(void);
extern void IIC_DS3231_WriteAll(u16 Year,u8 Month,u8 Date,u8 Week,u8 Hour,u8 Min,u8 Sec);
extern void IIC_DS3231_ReadAll(void);
extern u8 IIC_DS3231_ByteRead(u8 ReadAddr);
extern void IIC_DS3231_ByteWrite(u8 WriteAddr,u8 date);
extern u8 IIC_Read_Byte(const unsigned char ack);
extern void IIC_WriteByte(u8 data);
extern void IIC_NAck(void);
extern void IIC_Ack(void);
extern u8 IIC_Wait_Ask(void);
extern void IIC_Stop(void);
extern void IIC_Start(void);
extern void SDA_IN(void);
extern void SDA_OUT(void);
extern void IIC2_SoftInit(void);
extern void Sendtime(void);



#endif
